package com.whisperarts.financer.model.account;

import java.awt.Image;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.whisperarts.financer.model.currency.Currency;
import com.whisperarts.financer.model.transaction.Transaction;

public class Account {
	public static final String ACCOUNT_CASH = "Cash";
	public static final String ACCOUNT_CARD = "Card";
	public static final String ACCOUNT_WEB = "Web";
	public static final String ACCOUNT_BANK = "Bank";
	public static final String ACCOUNT_OTHER = "Other";

	public static final String[] CATEGORY = {ACCOUNT_CASH, ACCOUNT_CARD, ACCOUNT_WEB, ACCOUNT_BANK, ACCOUNT_OTHER};
	
	private int id;
	private String name;
	private Calendar dateOfCreation;
	private BigDecimal openingAmount;
	private Currency currency;
	private Image icon;
	private int accountType;
	private String note;
	private final List<Transaction> transactions = new ArrayList<Transaction>();
	
	public Account() {		
	}

	public Account(String name) {
		this.name = name;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Calendar getDateOfCreation() {
		return dateOfCreation;
	}
	public void setDateOfCreation(Calendar dateOfCreation) {
		this.dateOfCreation = dateOfCreation;
	}
	public BigDecimal getOpeningAmount() {
		return openingAmount;
	}
	public void setOpeningAmount(BigDecimal openingAmount) {
		this.openingAmount = openingAmount;
	}
	public Currency getCurrency() {
		return currency;
	}
	public void setCurrency(Currency currency) {
		this.currency = currency;
	}
	public Image getIcon() {
		return icon;
	}
	public void setIcon(Image icon) {
		this.icon = icon;
	}
	public int getAccountType() {
		return accountType;
	}
	public void setAccountType(int accountType) {
		this.accountType = accountType;
	}
	public String getNote() {		
		return note == null ? "" : note;
	}
	public void setNote(String note) {
		this.note = note;
	}
	
	public List<Transaction> getTransactions() {
		return transactions;
	}
	
	public List<String> getAccountInfo() {
		List<String> info = new ArrayList<String>();
		info.add(getName());
		info.add("Opening: " + getOpeningAmount() + " " + getCurrency());
		return info;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Account))
			return false;
		Account anotherAccount = (Account)obj;
		return this.getName().equals(anotherAccount.getName()) &&
			   this.getDateOfCreation().equals(anotherAccount.getDateOfCreation()) &&
			   this.getOpeningAmount().equals(anotherAccount.getOpeningAmount()) &&
			   this.getAccountType() == anotherAccount.getAccountType() &&
			   this.getNote().equals(anotherAccount.getNote()) &&
			   this.getCurrency().equals(anotherAccount.getCurrency());			   
	}
}
